<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script
            src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
        <link rel="stylesheet"
            href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
        <script
            src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
        <title>1</title>
    </head>
    <body class="container">
        <div class="form-group">
            <label for="name">商品名称</label><br>
            <input type="text" id="name" value="" placeholder="商品名称"/>
        </div>
        <div class="form-group d-inline-block">
            <label for="price">价格</label><br>
            <input type="text" id="price" placeholder="价格"/>
            <p id="price-tip"></p>
        </div>
        <div class="form-group d-inline-block">
            <label for="amount">数量</label><br>
            <input type="text" id="amount" placeholder="数量" />
            <p id="amount-tip"></p>
        </div>
        <div class="form-check">
            <input type="checkbox" class="form-check-input" name="check"
                id="new"/>
            <label for="new">新产品</label>
        </div>
        <div>
            <button type="button" id="add" class="btn-info" onclick="submit()">添加</button>
        </div>

        <script>
            var price=document.getElementById('price')
            var amount=document.getElementById('amount')
            var priceTip=document.getElementById('price-tip')
            var amountTip=document.getElementById('amount-tip')
            function submit(){
                if(Number(price.value)<=0){
                    alert('输入的价格必须是正数')
                    // priceTip.innerHTML='输入的价格必须是正数'
                } 
                if(Number(amount.value) % 1 != 0){
                    alert('输入的数量必须是正整数')
                    // amountTip.innerHTML='输入的数量必须是正整数'
                }
              
            }
    </script>
    </body>
</html>